<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>奖学金信息修改页面</title>
    <link rel="stylesheet" type="text/css" href="../static/admin/layui2/css/layui.css"/>
</head>
<body class="layui-layout-body">
        <div class="layui-anim layui-anim-scale">
            <form class="layui-form layui-form-pane" name="form1" id="form1" style="margin-left: 10px;margin-top: 10px;">
                <div class="layui-form-item">
                    <label class="layui-form-label">奖学金编号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="sid" id="sid" disabled class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">赞助人编号</label>
                    <div class="layui-input-inline">
                        <select name="aid" id="aid" lay-verify="required">
                            <option value=""></option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="name" id="name" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-inline state">
                        <input type="radio" name="state" value="1" title="启用" checked>
                        <input type="radio" name="state" value="0" title="禁用">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">开始时间</label>
                    <div class="layui-input-inline">
                        <input type="text" name="startTime" id="startTime" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">结束时间</label>
                    <div class="layui-input-inline">
                        <input type="text" name="endTime" id="endTime" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">金额</label>
                    <div class="layui-input-inline">
                        <input type="text" name="money" id="money" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">名额</label>
                    <div class="layui-input-inline">
                        <input type="text" name="sum" id="sum" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">剩余名额</label>
                    <div class="layui-input-inline">
                        <input type="text" name="residue" id="residue" lay-verify="required" class="layui-input" disabled>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">申请人数</label>
                    <div class="layui-input-inline">
                        <input type="text" name="applyNum" id="applyNum" lay-verify="required" class="layui-input" disabled>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">申请要求</label>
                    <div class="layui-input-inline">
                        <textarea name="require" id="require" class="layui-textarea" style="width: 500px"></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-inline">
                        <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">修改</button>
                    </div>
                </div>
            </form>
</div>
<script src="../static/admin/layui2/layui.js" type="text/javascript" charset="utf-8"></script>
<script>
    layui.use(['element','form','jquery','layer','laydate'], function(){
        var element = layui.element
        var form = layui.form
        laydate = layui.laydate
        layer = layui.layer
        $ =layui.jquery;


        laydate.render({
            elem: '#startTime' //指定元素
            ,type:'datetime',
            isInitValue: false,
            format: "yyyy-MM-dd HH:mm:ss",
            value:new Date(new Date().toLocaleDateString()),
            done: function(value, data, endData) {
                var endTime = new Date($('#endTime').val()).getTime();
                var startDate = new Date(value).getTime();
                if (endTime < startDate) {
                    layer.msg("结束时间不得小于开始时间!",{icon: 5});
                    value.val(" ")
                }

            }
        });
        laydate.render({
            elem: '#endTime' //指定元素
            ,type:'datetime',
            format: "yyyy-MM-dd HH:mm:ss",
            isInitValue: false,
            value:new Date(),
            done: function(value, date, endData) {
                var startDate = new Date($('#startTime').val()).getTime();
                var endTime = new Date(value).getTime();
                if (endTime < startDate) {
                    layer.msg("结束时间不得小于开始时间!",{icon: 5});
                    value.val(" ");
                }
            }

        });

        form.render();
        form.on('submit(demo1)',function (data) {
            $.ajax({
                type:"POST",
                url:"/scholarship/updataScholarship",
                data:{
                    "sid":data.field.sid,
                    "aid":data.field.aid,
                    "name": data.field.name,
                    "state": data.field.state,
                    "startTime":data.field.startTime,
                    "endTime": data.field.endTime,
                    "money":data.field.money,
                    "sum":data.field.sum,
                    "residue":data.field.residue,
                    "applyNum":data.field.applyNum,
                    "require":data.field.require,
                },
                dataType:"json",
                success:function (res) {
                    if (res.flag){
                        layer.msg('修改成功', {icon: 1});
                        setTimeout(function(){
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);//关闭弹出层
                            parent.location.reload();//重新加载父页面表格
                        }, 2100);
                    }else {
                        layer.msg(res.msg,{icon:5,offset:"auto",time:2000});//提示框
                    }
                }
            })
            return false;
        });
    });
</script>
</body>

</html>